﻿package Server.AHMJ.JZMJ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.ArrayUtils;

public class MajHelper {
	static int m_testMjPai[] = {
			1, 2, 3, 4, 5, 6, 7, 8, 9, // 1-9 一万-九万
			11, 12, 13, 14, 15, 16, 17, 18, 19, // 11-19一筒-九筒
			21, 22, 23, 24, 25, 26, 27, 28, 29, // 21-29 一条-九条
			31, 32, 33, 34, 35, 36, 37, // 31-37  东南西北中发白
	};
	public static void SortCard(int byHandCard[], int byHandMjCount) {
		for (int i = 0; i < byHandMjCount - 1; i++) {
			for (int j = i; j < byHandMjCount; j++) {
				int x = byHandCard[i];
				int y = byHandCard[j];

				if (x > y) {
					int tempvalue = byHandCard[i];
					byHandCard[i] = byHandCard[j];
					byHandCard[j] = tempvalue;
				}
			}
		}
	}
	
//	public static boolean IsHu(int byHandMj[], int byMj) {
//		return IsHu(byHandMj, byMj, new HU(), new HU(), null);
//	}
	public static int GetRelativeSeat(int bySeatID,int byLastOutUser){
		int currindex = bySeatID;
		int outindex = byLastOutUser;
		if(currindex == 3 && outindex == 0)
			outindex = 4;
		else if(currindex == 0 && outindex == 3)
			currindex = 4;
		if(currindex - outindex == 1)
			return 0;
		else if(outindex - currindex == 1)
			return 2;
		else
			return 1;
	}
	//////////////////////////////////////////////////////////////////////////
	// 0-8 一万-九万
	// 9-17 一条-九条w
	// 18-26 一筒-九筒
	// 27-33 东南西北中发白
	// 34-41 春夏秋冬梅兰竹菊
	//////////////////////////////////////////////////////////////////////////
	public static boolean IsHu(int byHandMj[], int byMj, HU hu, HU tempHu, int byHuaPai[],String m_ssl) {

		// 排序牌面
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, byHandMj, Constants.HAND_MJ_MAX);
		if (byMj != Constants.INVALID_CARD) {
			OriginalMj[Constants.HAND_MJ_MAX - 1] = byMj;
		}

		SortCard(OriginalMj, (int) Constants.HAND_MJ_MAX);
		if(m_ssl == "HBK" && MajHelper.IsPaiXinShiSanBuKao(OriginalMj)){
			return true;
		}
		if(m_ssl == "SBK" && MajHelper.IsPaiXinShiSanBuKao(OriginalMj) && MajHelper.SbkSSBK(OriginalMj)){
			return true;
		}
	 
		if (IsPaiXinQiDuiZi(OriginalMj) > 0) {
			return true;
		}
		
		if (IsGuoShiWuShuang(OriginalMj)) {
			return true;
		}
		// 将牌位在整数块( 0, 3, 6, 9, 12, 15 )处
		// 设置变量
		MJ_BLOCK block1;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {
			int tempMj[] = new int[Constants.HAND_MJ_MAX];
			Constants.memcpy(tempMj, OriginalMj, Constants.HAND_MJ_MAX);
			if (IsJiang(tempMj[i], tempMj[i + 1])) {
				// 胡牌结构处理
				CleanHu(tempHu);
				CopyHu(tempHu, hu);
				tempHu.jiangMj = tempMj[i];
				tempMj[i] = Constants.INVALID_CARD;
				tempMj[i + 1] = Constants.INVALID_CARD;
				SortCard(tempMj, (int) Constants.HAND_MJ_MAX);
				// 单钓
				if (tempHu.block[(Constants.HAND_MJ_MAX - 2) / 3 - 1].style != Constants.BLOCK_NULL) {
					return true;
				}
				for (int j = 0; j < Constants.HAND_MJ_MAX - 2; j += 3) {

					block1 = CheckBlock(tempMj[j], tempMj[j + 1], tempMj[j + 2]);
					if (block1.style != Constants.BLOCK_NULL) {
						AddBlock(tempHu, block1);
					} else {
						// 有相嵌的两个BLOCK结构,或三个BLOCK结构
						if (j + 5 <= Constants.HAND_MJ_MAX - 1) {
							MJ_BLOCK block2;
							// 两种情况 223344 或 233334 或 233444556 或 233344455 或
							// 334445556
							// 情况1 223344 233445
							block1 = CheckBlock(tempMj[j], tempMj[j + 2], tempMj[j + 4]);
							block2 = CheckBlock(tempMj[j + 1], tempMj[j + 3], tempMj[j + 5]);
							if (block1.style != Constants.BLOCK_NULL && block2.style != Constants.BLOCK_NULL) {
								AddBlock(tempHu, block1);
								AddBlock(tempHu, block2);
								j += 3;
							}
							// 情况2 233334
							else {
								block1 = CheckBlock(tempMj[j], tempMj[j + 1], tempMj[j + 5]);
								block2 = CheckBlock(tempMj[j + 2], tempMj[j + 3], tempMj[j + 4]);
								if (block1.style != Constants.BLOCK_NULL && block2.style != Constants.BLOCK_NULL) {
									AddBlock(tempHu, block1);
									AddBlock(tempHu, block2);
									j += 3;
								}
								// 情况3 233444556
								else {
									if (j + 8 <= Constants.HAND_MJ_MAX - 1) {
										MJ_BLOCK block3 = new MJ_BLOCK();
										block1 = CheckBlock(tempMj[j], tempMj[j + 1], tempMj[j + 3]);
										block2 = CheckBlock(tempMj[j + 2], tempMj[j + 4], tempMj[j + 6]);
										block3 = CheckBlock(tempMj[j + 5], tempMj[j + 7], tempMj[j + 8]);
										if (block1.style != Constants.BLOCK_NULL && block2.style != Constants.BLOCK_NULL
												&& block3.style != Constants.BLOCK_NULL) {
											AddBlock(tempHu, block1);
											AddBlock(tempHu, block2);
											AddBlock(tempHu, block3);
											j += 6;
										}
										// 情况3 334445556
										else {
											MJ_BLOCK block31 = new MJ_BLOCK();
											block1 = CheckBlock(tempMj[j], tempMj[j + 1], tempMj[j + 4]);
											block2 = CheckBlock(tempMj[j + 2], tempMj[j + 5], tempMj[j + 7]);
											block31 = CheckBlock(tempMj[j + 3], tempMj[j + 6], tempMj[j + 8]);
											if (block1.style != Constants.BLOCK_NULL
													&& block2.style != Constants.BLOCK_NULL
													&& block31.style != Constants.BLOCK_NULL) {
												AddBlock(tempHu, block1);
												AddBlock(tempHu, block2);
												AddBlock(tempHu, block31);
												j += 6;
											} else {
												block1 = CheckBlock(tempMj[j], tempMj[j + 2], tempMj[j + 5]);
												block2 = CheckBlock(tempMj[j + 1], tempMj[j + 3], tempMj[j + 6]);
												block31 = CheckBlock(tempMj[j + 4], tempMj[j + 7], tempMj[j + 8]);
												if (block1.style != Constants.BLOCK_NULL
														&& block2.style != Constants.BLOCK_NULL
														&& block31.style != Constants.BLOCK_NULL) {
													AddBlock(tempHu, block1);
													AddBlock(tempHu, block2);
													AddBlock(tempHu, block31);
													j += 6;
												}
											}
										}
									}
								}
							}

						} else {
							break;
						}
					}
					if (tempHu.block[(Constants.HAND_MJ_MAX - 2) / 3 - 1].style != Constants.BLOCK_NULL) {
						return true;
					}
				}
			}
		}

		return false;
	}

	public static boolean IsTing(int byHandMj[], int byMj, HU hu, int intstMj[], int intstMjCount, int byHuaPai[]) {
		int byHandMjCount = 0;
		for (int byIndex = 0; byIndex < Constants.HAND_MJ_MAX; byIndex++) {
			if (MajHelper.IsWTSZ(byHandMj[byIndex])) {
				byHandMjCount++;
			}
		}
		for (int byIndex = 0; byIndex < Constants.HAND_MJ_MAX; byIndex++) {
			int intmpMj[] = new int[Constants.HAND_MJ_MAX];
			Constants.memcpy(intmpMj, byHandMj, Constants.HAND_MJ_MAX);
			if (((byHandMjCount
					% 3) == 2) /* && (byMj == Constants.INVALID_CARD) */) {
				intmpMj[byIndex] = Constants.INVALID_CARD;
			}
			if (byIndex != Constants.HAND_MJ_MAX - 1) {
				intmpMj[Constants.HAND_MJ_MAX - 1] = byMj;
			}

			SortCard(intmpMj, (int) Constants.HAND_MJ_MAX);
			for (int i = 0; i < intstMjCount; i++) {
				int intstMjValue = intstMj[i];
				HU tempHu = new HU();
				CleanHu(tempHu);
//				if (IsHu(intmpMj, intstMjValue, hu, tempHu, byHuaPai)) {
//					return true;
//				}
			}
		}
		return false;
	}

	public static int GetTingPai(int byHandMj[], HU hu, int byHuaPai[], int byResultTingMj[],String m_ssl) {
		int byTingPaiCount = 0;
		int intmpMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(intmpMj, byHandMj, Constants.HAND_MJ_MAX);
		intmpMj[Constants.HAND_MJ_MAX - 1] = Constants.INVALID_CARD;

		SortCard(intmpMj, Constants.HAND_MJ_MAX);


		for (int i = 0; i < 34; i++) {
			int byMj = m_testMjPai[i];
			HU tempHu = new HU();
			CleanHu(tempHu);
			if (IsHu(intmpMj, byMj, hu, tempHu, byHuaPai,m_ssl)) {
				byResultTingMj[byTingPaiCount++] = byMj;
			}
		}

		return byTingPaiCount;
	}

	public static int GetPaiCount(int byHandMj[]) {
		int cnt = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (byHandMj[i] != Constants.INVALID_CARD) {
				cnt++;
			}
		}
		return cnt;
	}

	public static int GetPaiCount(int byHandMj[], int byMj) {
		int cnt = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (byHandMj[i] == byMj) {
				cnt++;
			}
		}
		return cnt;
	}

	public static int GetChiSelect(int byHandMj[], int byMj, HU tempHu) {
		int byMask = IsChi(byHandMj, byMj);
		int byIndex = 0;
		// 吃牌信息, 0-无吃牌,1-**@型, 2-*@*, 4-@**型
		if (TestBit(byMask, 0)) {
			tempHu.block[byIndex].first = byMj - 2;
			tempHu.block[byIndex].style = Constants.BLOCK_SUN;
			byIndex++;
		}
		if (TestBit(byMask, 1)) {
			tempHu.block[byIndex].first = byMj - 1;
			tempHu.block[byIndex].style = Constants.BLOCK_SUN;
			byIndex++;
		}
		if (TestBit(byMask, 2)) {
			tempHu.block[byIndex].first = byMj;
			tempHu.block[byIndex].style = Constants.BLOCK_SUN;
			byIndex++;
		}
		return byIndex;
	}

	public static boolean TestBit(int var, int bit) {
		return ((var) & (1 << (bit))) != 0;
	}

	// 加入块到胡牌结构
	public static int AddBlock(HU hu, PTR_MJ_BLOCK block) {
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].style == Constants.BLOCK_NULL) {
				hu.block[i].first = block.first;
				hu.block[i].style = block.style;
				hu.block[i].origValue = block.origValue;
				return i;
			}
		}
		return 255;
	}

	public static int AddBlock(HU hu, BLOCK block) {
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].style == Constants.BLOCK_NULL) {
				hu.block[i].first = block.first;
				hu.block[i].style = block.style;
				hu.block[i].origValue = block.origValue;
				return i;
			}
		}
		return 255;
	}

	public static int AddBlock(HU hu, MJ_BLOCK block) {
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].style == Constants.BLOCK_NULL) {
				hu.block[i].first = block.first;
				hu.block[i].style = block.style;
				hu.block[i].origValue = block.origValue;
				if(block.OutUserGang!=-1){
					hu.block[i].OutUserGang = block.OutUserGang;
				}
				return i;
			}
		}
		return 255;
	}

	// 类型判断
	public static MJ_BLOCK CheckBlock(int byMj1, int byMj2, int byMj3) {
		MJ_BLOCK block = new MJ_BLOCK();
		block.first = Constants.INVALID_CARD;
		block.style = Constants.BLOCK_NULL;

		if (byMj1 == Constants.INVALID_CARD || byMj2 == Constants.INVALID_CARD || byMj3 == Constants.INVALID_CARD) {
			return block;
		}
		if (IsTongHuaSe(byMj1, byMj2, byMj3) == false) {
			return block;
		}
		// 如果byMj1, byMj2, byMj3不是顺序结构,排序
		int i, tag, temp;
		for (i = 0, tag = 1; tag == 1 && i < 3; i++) {
			tag = 0;
			if (byMj1 > byMj2) {
				temp = byMj1;
				byMj1 = byMj2;
				byMj2 = temp;
				tag = 1;
			}
			if (byMj2 > byMj3) {
				temp = byMj2;
				byMj2 = byMj3;
				byMj3 = temp;
				tag = 1;
			}
		}

		// 碰形结构
		if (byMj1 == byMj2 && byMj2 == byMj3) {
			block.first = byMj1;
			block.style = Constants.BLOCK_KE;
			return block;
		}

		// 顺形结构
		if (IsWST(byMj3) && IsWST(byMj1)) // 不为字, 花
		{
			if (byMj3 == byMj2 + 1 && byMj2 == byMj1 + 1) {
				block.first = byMj1;
				block.style = Constants.BLOCK_SUN;
				return block;
			}
		}
		return block;
	}

	// 是否可以做将牌
	public static boolean IsJiang(int byMj1, int byMj2) {
		if (byMj1 == byMj2 && MajHelper.IsWTSZ(byMj1)) {
			return true;
		}
		return false;
	}

	public static boolean IsTongHuaSe(int byMj1, int byMj21, int byMj31) {
		int byMj2 = byMj21;
		int byMj3 = byMj31;
		if (IsWan(byMj1) && IsWan(byMj2) && IsWan(byMj3) ) {
			return true;
		}
		if (IsTong(byMj1) && IsTong(byMj2) && IsTong(byMj3) ) {
			return true;
		}
		if (IsSuo(byMj1) && IsSuo(byMj2) && IsSuo(byMj3) ) {
			return true;
		}

		if ((byMj1 == byMj2) && (byMj2 == byMj3) && MajHelper.IsWTSZ(byMj1)) {
			return true;
		}
		return false;
	}

	public static boolean IsTongHuaSe(int byMj1, int byMj2) {
		if (IsWan(byMj1) && IsWan(byMj2) ) {
			return true;
		}
		if (IsTong(byMj1) && IsTong(byMj2) ) {
			return true;
		}
		if (IsSuo(byMj1) && IsSuo(byMj2)  ) {
			return true;
		}

		if (byMj1 == byMj2 && MajHelper.IsWTSZ(byMj1)) {
			return true;
		}
		return false;
	}
	public static boolean IsWTSZ(int byMj)
	{
		if(byMj >= 1 && byMj <=9)//一万~九万
		{
			return true;
		}
		if(byMj >= 11 && byMj <=19)//一筒~九筒
		{
			return true;
		}
		if(byMj >= 21 && byMj <=29)//一条~九条
		{
			return true;
		}
		if(byMj >= 31 && byMj <=37)//东南西北中发白
		{
			return true;
		}
		if(byMj >= 41 && byMj <=48)//春夏秋冬梅兰竹菊
		{
			return true;
		}
		return false;
	}
	// 是否是万索筒
	public static boolean IsWST(int byMj1) {
		if (IsWan(byMj1)) {
			return true;
		}
		if (IsTong(byMj1)) {
			return true;
		}
		if (IsSuo(byMj1)) {
			return true;
		}
		return false;
	}

	public static boolean IsWan(int byMj1) {
		if (byMj1 >= 1 && byMj1 <= 9) {
			return true;
		}
		return false;
	}

	public static boolean IsTong(int byMj1) {
		if (byMj1 >= 11 && byMj1 <= 19) {
			return true;
		}
		return false;
	}

	public static boolean IsSuo(int byMj1) {
		if (byMj1 >= 21 && byMj1 <= 29) {
			return true;
		}
		return false;
	}
	// 是否是风牌
	public static boolean IsZi(int byMj1) {
		if (byMj1 >= 31 && byMj1 <= 37) {
			return true;
		}
		return false;
	}
	// 是否是风牌
	public static boolean IsFeng(int byMj1) {
		if (byMj1 >= 31 && byMj1 <= 37) {
			return true;
		}
		return false;
	}

	// 是否是三元
	public static boolean IsSanYuan(int byMj1) {
		if (byMj1 >= 35 && byMj1 <= 37) {
			return true;
		}
		return false;
	}
	// 是否是花
	public static boolean IsHua(int byMj1) {
		if (byMj1 >= 41 && byMj1 <= 48) {
			return true;
		}
		return false;
	}
	public static int GetNextUser(int bySeatID) {
		return (bySeatID + 1) % 4;
	}

	// 是否是花牌
	public static boolean IsHuaPai(int byPai) {
		if (byPai >= 41 && byPai <= 48) {
			return true;
		}
		return false;
	}

	// 是否可以吃牌
	public static int IsChi(int byHandMj[], int byMj) {
		// 风,字不能上
		if (byMj >= 31) {
			return 0;
		}
		int chiInfo = 0; // 吃牌信息, 0-无吃牌,1-**@型, 2-*@*, 4-@**型
		boolean pos2, pos1, pos;
		pos2 = pos1 = pos = true;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {
			// **@
			if (byHandMj[i] == byMj - 2 && pos2) {
				for (int j = i; j < Constants.HAND_MJ_MAX - 1; j++) {
					if (byHandMj[j] == byMj - 1 && IsTongHuaSe(byMj, byMj - 1, byMj - 2)) {
						chiInfo += 1; // 吃牌类型1
						break;
					}
				}
				pos2 = false;
			}
			// *@*
			else if (byHandMj[i] == byMj - 1 && pos1) {
				for (int j = i; j < Constants.HAND_MJ_MAX - 1; j++) {
					if (byHandMj[j] == byMj + 1 && IsTongHuaSe(byMj, byMj - 1, byMj + 1)) {
						chiInfo += 2; // 吃牌类型2
						break;
					}
				}
				pos1 = false;
			}
			// @**
			else if (byHandMj[i] == byMj + 1 && pos) {
				for (int j = i; j < Constants.HAND_MJ_MAX - 1; j++) {
					if (byHandMj[j] == byMj + 2 && IsTongHuaSe(byMj, byMj + 1, byMj + 2)) {
						chiInfo += 4; // 吃牌类型2
						break;
					}
				}
				pos = false;
			}
		}
		return chiInfo;
	}

	// 是否可以碰牌
	public static boolean IsPeng(int byHandMj[], int byMj) {
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1 - 1; i++) {
			if (byHandMj[i] == byMj && byHandMj[i + 1] == byMj && IsTongHuaSe(byMj, byHandMj[i], byHandMj[i + 1])) {
				return true;
			}
		}
		return false;
	}

	// 是否明杠
	public static MJ_GANGINFO IsGang(int byHandMj[], int byMj) {
		MJ_GANGINFO gangInfo = new MJ_GANGINFO();
		gangInfo.GangStyle = 0;
		gangInfo.GangMj = 0;
		// 明杠手上不会有第十四张牌
		for (int i = 0; i < Constants.HAND_MJ_MAX - 3; i++) {
			if (byHandMj[i] == byMj && byHandMj[i + 1] == byMj && byHandMj[i + 2] == byMj) {
				gangInfo.GangMj = byHandMj[i];
				gangInfo.GangStyle = 1;
			}
		}
		return gangInfo;
	}

	public static MJ_GANGINFO IsZMGang(int byHandMj[], HU hu) {
		return IsZMGang(byHandMj, hu, 255, 255, 255);
	}
	public static boolean IsCanGangNoBaoZi(int byHandMj[], HU hu, int byMj){
		if(IsShunQiGang(byHandMj,hu,byMj)){
			return true;
		}else{
			for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
				if (hu.block[i].style == Constants.BLOCK_PENG)
				{
					int num = getCardNumber(byHandMj,hu.block[i].first);
					if(num >= 1)
						return true;
				}
			}
		}
		if(IsAnGang(byHandMj).GangStyle != 0){
			return true;
		}
		return false;
	}
	public static int getCardNumber(int byHandMj[],int mj){
		int num = 0;
		for(int i = 0;i < byHandMj.length;i++){
			if(byHandMj[i] == mj)
				num++;
		}
		return num;
	}
	// 自摸明杠 返回,
	public static boolean IsShunQiGang(int byHandMj[], HU hu, int byMj) {
		MJ_GANGINFO gangInfo = new MJ_GANGINFO();
		gangInfo.GangStyle = 0;
		gangInfo.GangMj = Constants.INVALID_CARD;
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].style == Constants.BLOCK_PENG && hu.block[i].first == byMj)
			{
				return true;
			}
		}
		return false;
	}
	
	// 自摸明杠 返回,
	public static MJ_GANGINFO IsZMGang(int byHandMj[], HU hu, int jPos1, int jPos2, int jPos3) {
		MJ_GANGINFO gangInfo = new MJ_GANGINFO();
		gangInfo.GangStyle = 0;
		gangInfo.GangMj = Constants.INVALID_CARD;
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].style == Constants.BLOCK_NULL)
				break;
			else if (hu.block[i].style != Constants.BLOCK_PENG)
				continue;
			else {
				// 跳过多个补杠
				if (hu.block[i].first == jPos1 || hu.block[i].first == jPos2 || hu.block[i].first == jPos3)
					continue;
				for (int j = 0; j < Constants.HAND_MJ_MAX; j++) {
					// if( byHandMj[j]==jPos1 || byHandMj[j]==jPos2 )
					// continue;
					if (byHandMj[j] == hu.block[i].first) {
						gangInfo.GangStyle = 2; // 自摸明杠
						gangInfo.GangMj = byHandMj[j]; // 明杠胡牌块位
						return gangInfo;
					}
				}
			}
		}
		return gangInfo;
	}

	public static MJ_GANGINFO IsAnGang(int byHandMj[]) {
		return IsAnGang(byHandMj, 255, 255, 255);
	}

	public static MJ_GANGINFO IsAnGang(int byHandMj[], int jPos1) {
		return IsAnGang(byHandMj, jPos1, 255, 255);
	}

	public static MJ_GANGINFO IsAnGang(int byHandMj[], int jPos1, int jPos2) {
		return IsAnGang(byHandMj, jPos1, jPos2, 255);
	}

	// 是否暗杠
	public static MJ_GANGINFO IsAnGang(int byHandMj[], int jPos1, int jPos2, int jPos3) {
		MJ_GANGINFO gangInfo = new MJ_GANGINFO();
		gangInfo.GangStyle = 0;
		gangInfo.GangMj = Constants.INVALID_CARD;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 3; i++) {
			// 跳过
			if (byHandMj[i] == jPos1 || byHandMj[i] == jPos2 || byHandMj[i] == jPos3)
				continue;
			if (byHandMj[i] == byHandMj[i + 1] && byHandMj[i] == byHandMj[i + 2]) {
				// 手上有杠牌
				if (byHandMj[i] == byHandMj[i + 3]) {
					gangInfo.GangStyle = 4;
					gangInfo.GangMj = byHandMj[i];
				}
				// 刚摸到杠牌
				else if (byHandMj[i] == byHandMj[Constants.HAND_MJ_MAX - 1]) {
					gangInfo.GangStyle = 4;
					gangInfo.GangMj = byHandMj[i];
				}
			}
		}
		return gangInfo;
	}

	// 清除胡牌数据
	public static void CleanHu(HU hu) {
		hu.jiangMj = Constants.INVALID_CARD;
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i] == null) {
				hu.block[i] = new BLOCK();
			}
			hu.block[i].first = Constants.INVALID_CARD;
			hu.block[i].style = Constants.BLOCK_NULL;
		}
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			hu.sanMj[i] = Constants.INVALID_CARD;
		}
	}

	// 拷贝胡牌数据
	public static void CopyHu(HU destHu, HU srcHu) {
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			destHu.block[i].first = srcHu.block[i].first;
			destHu.block[i].style = srcHu.block[i].style;
		}
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			destHu.sanMj[i] = srcHu.sanMj[i];
		}
	}

	public static void HuToHandMj(int byMjs[], HU srcHu) {
		int j = 0;
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			switch (srcHu.block[i].style) {
			case Constants.BLOCK_NULL: {

			}
				break;
			case Constants.BLOCK_CHI: {
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = (srcHu.block[i].first + 1);
				byMjs[j++] = (srcHu.block[i].first + 2);
			}
				break;
			case Constants.BLOCK_SUN: // 顺序结构
			{
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = (srcHu.block[i].first + 1);
				byMjs[j++] = (srcHu.block[i].first + 2);
			}
				break;
			case Constants.BLOCK_PENG: // 碰子结构,3个相同
			{
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
			}
				break;
			case Constants.BLOCK_KE: // 刻子结构,3个相同,非碰
			{
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
			}
				break;
			case Constants.BLOCK_GANG: // 杠子结构,4个相同
			case Constants.BLOCK_BU_GANG:
			{
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
			}
				break;
			case Constants.BLOCK_AN_GANG: // 暗杠
			{
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
				byMjs[j++] = srcHu.block[i].first;
			}
				break;
			}
		}
		int srcHujiangMj = srcHu.jiangMj;
		byMjs[j++] = srcHujiangMj;
		byMjs[j++] = srcHujiangMj;
	}

	public static int DeletePai(int byHandMj[], int byMj1) {
		return DeletePai(byHandMj, byMj1, 255, 255);
	}

	public static int DeletePai(int byHandMj[], int byMj1, int byMj2) {
		return DeletePai(byHandMj, byMj1, byMj2, 255);
	}

	public static int DeletePai(int byHandMj[], int byMj1, int byMj2, int byMj3) {
		int cnt = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (byHandMj[i] == byMj1 && byMj1 != Constants.INVALID_CARD) {
				byHandMj[i] = Constants.INVALID_CARD;
				byMj1 = Constants.INVALID_CARD;
				cnt++;
			}
			if (byHandMj[i] == byMj2 && byMj2 != Constants.INVALID_CARD) {
				byHandMj[i] = Constants.INVALID_CARD;
				byMj2 = Constants.INVALID_CARD;
				cnt++;
			}
			if (byHandMj[i] == byMj3 && byMj3 != Constants.INVALID_CARD) {
				byHandMj[i] = Constants.INVALID_CARD;
				byMj3 = Constants.INVALID_CARD;
				cnt++;
			}
		}
		SortCard(byHandMj, Constants.HAND_MJ_MAX);
		return cnt;
	}

	public static void AdjustChiHu(HU hu, int byHuMj) {
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_KE: {
				if (hu.block[i].first == byHuMj) {
					hu.block[i].style = Constants.BLOCK_PENG;
				}
			}
			default:
				break;
			}
		}
	}

	// 分析胡牌类型,返回番数
	public static long CheckGDHu(HU hu, int byFengWei, int byQuanWei, char strFang) {
		return 0;
	}

	public static BLOCK Peng(int byMjs[], int byMj) {
		MJ_BLOCK block = new MJ_BLOCK();
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {
			if (byMjs[i] == byMj && byMjs[i + 1] == byMj) {// 普通碰
				byMjs[i] = Constants.INVALID_CARD;
				byMjs[i + 1] = Constants.INVALID_CARD;
				// 右移3格
				break;
			}
		}
		block.first = byMj;
		block.style = Constants.BLOCK_PENG;
		return block;
	}

	// 杠操作
	public static BLOCK MGang(int byMjs[], int byMj,int CurrentUser) {
		MJ_BLOCK block = new MJ_BLOCK();
		block.style = Constants.BLOCK_NULL;
		block.first = -1;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 3; i++) {
			if (byMjs[i] == byMj) {
				byMjs[i] = Constants.INVALID_CARD;
				byMjs[i + 1] = Constants.INVALID_CARD;
				byMjs[i + 2] = Constants.INVALID_CARD;
				block.style = Constants.BLOCK_GANG;
				block.first = byMj;
				// 右移4格
				block.OutUserGang = CurrentUser;
				return block;
			}
		}
		return block;
	}

	// 自摸明杠-补杠
	public static void ZMGang(int byMjs[], HU hu, int GangMj) {
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			if (hu.block[i].first == GangMj) {
				hu.block[i].style = Constants.BLOCK_BU_GANG;
				break;// 右移一格
			}
		}
		for (int j = 0; j < Constants.HAND_MJ_MAX; j++) {
			if (byMjs[j] == GangMj) {
				byMjs[j] = Constants.INVALID_CARD;
				break;
			}
		}
	}

	// 暗杠
	public static BLOCK AnGang(int byMjs[], int GangMj) {
		MJ_BLOCK block = new MJ_BLOCK();
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (byMjs[i] == GangMj) {
				byMjs[i] = Constants.INVALID_CARD;
			}
		}
		block.style = Constants.BLOCK_AN_GANG;
		block.first = GangMj;
		return block;
	}

	// 吃牌操作
	public static BLOCK Chi(int byMjs[], int byMj, int ChiMode) {
		MJ_BLOCK block = new MJ_BLOCK();
		block.first = 0;
		block.style = Constants.BLOCK_NULL;
		block.origValue = byMj;
		switch (ChiMode) {
		case 1: // @@*
		{
			block.first = (byMj - 2);
			block.style = Constants.BLOCK_CHI;
			// 清零麻将
			for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
				if (byMjs[i] == byMj - 2) {
					byMjs[i] = Constants.INVALID_CARD;
					for (int j = i; j < Constants.HAND_MJ_MAX; j++) {
						if (byMjs[j] == byMj - 1) {
							byMjs[j] = Constants.INVALID_CARD;
							return block;
						}
					}
					break;
				}
			}
		}
			break;
		case 2: // @*@
		{
			block.first = (byMj - 1);
			block.style = Constants.BLOCK_CHI;
			// 清零麻将
			for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
				if (byMjs[i] == byMj - 1) {
					byMjs[i] = Constants.INVALID_CARD;
					for (int j = i; j < Constants.HAND_MJ_MAX; j++) {
						if (byMjs[j] == byMj + 1) {
							byMjs[j] = Constants.INVALID_CARD;
							return block;
						}
					}
					break;
				}
			}
		}
			break;
		case 4: // *@@
		{
			block.first = byMj;
			block.style = Constants.BLOCK_CHI;
			// 清零麻将
			for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
				if (byMjs[i] == byMj + 1) {
					byMjs[i] = Constants.INVALID_CARD;
					for (int j = i; j < Constants.HAND_MJ_MAX; j++) {
						if (byMjs[j] == byMj + 2) {
							byMjs[j] = Constants.INVALID_CARD;
							return block;
						}
					}
					break;
				}
			}
		}
			break;
		}
		return block;
	}

	public static int GetFengZiKe(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsFeng(hu.block[i].first)) {
				total++;
			}
		}
		return total;
	}

	public static int GetSanYuanKe(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsSanYuan(hu.block[i].first)) {
				total++;
			}
		}
		return total;
	}

	public static int GetPaiXinAnKe(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_KE:
			case Constants.BLOCK_AN_GANG: {
				total++;
			}
			}
		}
		return total;
	}

	public static boolean IsBaXianGuoHai(int byHuaPai[], int byMj) {
		int iHuaCount = 0;
		for (int j = 0; j < 8; j++) {
			if (IsHuaPai(byHuaPai[j])) {
				iHuaCount++;
			}
		}
		if (IsHuaPai(byMj)) {
			iHuaCount++;
		}
		if (iHuaCount == 8) {
			return true;
		} else {
			return false;
		}
	}

	// 平胡
	public static boolean IsPaiXinPinHu(int tempMj[], HU hu, int byMj) {
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (tempMj[i] >= 31) {
				return false;
			}
		}
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				return false;
			}
			}
		}
		if (hu.jiangMj >= 31) {
			return false;
		}
		boolean bDuTing = false;
		boolean bDuoTing = false;
		int sunMjtotal = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_SUN: {
				sunMjtotal++;
				if (hu.block[i].first == byMj) // @**
				{
					if (hu.block[i].first % 10 == 7) // 7,89
					{
						bDuTing = true;
					} else {
						bDuoTing = true;
					}
				}
				if (hu.block[i].first == byMj - 1 && IsTongHuaSe(byMj, byMj - 1)) // *@*
				{
					bDuTing = true;
				}
				if (hu.block[i].first == byMj - 2 && IsTongHuaSe(byMj, byMj - 2)) // **@
				{
					if (hu.block[i].first % 10 == 1) // 12,3
					{
						bDuTing = true;
					} else {
						bDuoTing = true;
					}
				}
			}
				break;
			default: {
				return false;
			}
			}
		}
		if (sunMjtotal == 4) {
			if (bDuoTing) {
				return true;
			}
		}
		return false;
	}
	//遍历手中的牌
	public static boolean IsPaiXinShiSanBuKao(int tempMj[]){
		int count255=0;
		for(int i=0;i<tempMj.length;i++){
			if(tempMj[i]==255){
				count255++;
			}
		}
		if(count255>0){
			return false;
		}
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, tempMj, Constants.HAND_MJ_MAX);
		SortCard(OriginalMj, (int) Constants.HAND_MJ_MAX);
		for(int i=0;i<OriginalMj.length-1;i++){
			if(OriginalMj[i]==OriginalMj[i+1]){
				return false;
			}
		}
		for (int i = 0; i <= OriginalMj.length - 2; i++) {
			if (IsWan(OriginalMj[i])) {
				if (OriginalMj[i] == 9) {
				} else {
					if (OriginalMj[i] + 1 == OriginalMj[i + 1]
							|| OriginalMj[i] + 2 == OriginalMj[i + 1]) {
						return false;
					}
				}
			}
			if (IsSuo(OriginalMj[i])) {
				if (OriginalMj[i] == 29) {
				} else {
					if (OriginalMj[i] + 1 == OriginalMj[i + 1]
							|| OriginalMj[i] + 2 == OriginalMj[i + 1]) {
						return false;
					}
				}
			}
			if (IsTong(OriginalMj[i])) {
				if (OriginalMj[i] == 19) {
				} else {
					if (OriginalMj[i] + 1 == OriginalMj[i + 1]
							|| OriginalMj[i] + 2 == OriginalMj[i + 1]) {
						return false;
					}
				}
			}
		}
		return true;
	}

	public static boolean SbkSSBK(int tempMj[]){
		int wan[] = new int[3];
		int tong[] = new int[3];
		int tiao[] = new int[3];
		int wans = 0;
		int tongs = 0;
		int tiaos = 0;
		for(int i=0;i<tempMj.length;i++){
			if(IsWan(tempMj[i])){
				for(int j=0;j<3;j++){
					if(wan[j] == 0){
						wan[j] = tempMj[i];
						wans++;
						break;
					}
				}
			}
			if(IsTong(tempMj[i])){
				for(int j=0;j<3;j++){
					if(tong[j] == 0){
						tong[j] = tempMj[i];
						tongs++;
						break;
					}
				}
			}
			if(IsSuo(tempMj[i])){
				for(int j=0;j<3;j++){
					if(tiao[j] == 0){
						tiao[j] = tempMj[i];
						tiaos++;
						break;
					}
				}
			}
		}		
		if(wans == 3){
			if(wan[1]-wan[0] != wan[2]-wan[1]){
				return false;
			}
		}
		if(tongs == 3){
			if(tong[1]-tong[0] != tong[2]-tong[1]){
				return false;
			}
		}
		if(tiaos == 3){
			if(tiao[1]-tiao[0] != tiao[2]-tiao[1]){
				return false;
			}
		}
		if(wans == 2){
			if(wan[1]-wan[0] != 3 && wan[1]-wan[0] != 6){
				return false;
			}
		}
		if(tongs == 2){
			if(tong[1]-tong[0] != 3 && tong[1]-tong[0] != 6){
				return false;
			}
		}
		if(tiaos == 2){
			if(tiao[1]-tiao[0] != 3 && tiao[1]-tiao[0] != 6){
				return false;
			}
		}
		return true;
	}
	
	public static boolean IsPaiXinMenQing(int tempMj[], HU hu) {
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_GANG: {
				return false;
			}
			}
		}
		return true;
	}

	public static boolean IsPaiXinQuanQiu(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_GANG: {
				total++;
			}
				break;
			}
		}
		if (total == Constants.MAX_BLOCK_NUM) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean IsPaiXinZiYiSe(int tempMj[], HU hu) {
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (IsFeng(tempMj[i]) || IsSanYuan(tempMj[i])) {
			} else {
				return false;
			}
		}
		return true;
	}

	public static boolean IsPaiXinCouYiSe(int tempMj[], HU hu) {
		int iWanCount = 0, iSuoCount = 0, iTongCount = 0, iZiCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (IsWan(tempMj[i])) {
				iWanCount++;
			} else if (IsTong(tempMj[i])) {
				iSuoCount++;
			} else if (IsSuo(tempMj[i])) {
				iTongCount++;
			} else if (IsZi(tempMj[i])) {
				iZiCount++;
			}
		}
		if (iZiCount == Constants.HAND_MJ_MAX) {
			return false;
		}
		if (iWanCount + iZiCount == Constants.HAND_MJ_MAX || iSuoCount + iZiCount == Constants.HAND_MJ_MAX
				|| iTongCount + iZiCount == Constants.HAND_MJ_MAX) {
			return true;
		}
		return false;
	}

	public static boolean IsPaiXinSiAnKe(int tempMj[], HU hu) {
		if (GetPaiXinAnKe(tempMj, hu) == 4) {
			return true;
		}
		return false;
	}

	// 断幺九
	public static boolean IsPaiXinDuanYaoJiu(int tempMj[], HU hu) {
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (IsZi(tempMj[i]) || tempMj[i] % 10 == 1 || tempMj[i] % 10 == 9) {
				return false;
			}
		}
		return true;
	}

	// 一杯口
	public static boolean IsPaiXinYiBeiKou(int tempMj[], HU hu) {
		if (!IsPaiXinMenQing(tempMj, hu)) {
			return false;
		}
		int total = 0;
		int bySunMj[] = new int[5];

		Constants.memset(bySunMj, Constants.INVALID_CARD, Constants.sizeof(bySunMj));

		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_SUN: {
				bySunMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		int bei_kou = 0;
		if (total >= 2) {
			for (int j = 0; j < total - 1; j++) {
				if (bySunMj[j] == bySunMj[j + 1]) {
					bei_kou++;
					j += 1;
				}
			}
		}
		if (bei_kou == 1) {
			return true;
		}
		return false;
	}

	// 二杯口
	public static boolean IsPaiXinErBeiKou(int tempMj[], HU hu) {
		if (!IsPaiXinMenQing(tempMj, hu)) {
			return false;
		}
		int total = 0;
		int bySunMj[] = new int[5];

		Constants.memset(bySunMj, Constants.INVALID_CARD, Constants.sizeof(bySunMj));

		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_SUN: {
				bySunMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		int bei_kou = 0;
		if (total >= 2) {
			for (int j = 0; j < total - 1; j++) {
				if (bySunMj[j] == bySunMj[j + 1]) {
					bei_kou++;
					j += 1;
				}
			}
		}
		if (bei_kou == 2) {
			return true;
		}
		return false;
	}

	// 七对子
	public static int IsPaiXinQiDuiZi(int byTempMj[]) {
		/*
		 * for (int i = 0; i < Constants.HAND_MJ_MAX - 3; i += 1) { if
		 * ((byHandMj[i] != Constants.INVALID_CARD) && (byHandMj[i] ==
		 * byHandMj[i + 1]) && (byHandMj[i] == byHandMj[i + 2]) && (byHandMj[i]
		 * == byHandMj[i + 3]) ) { return 0; } }
		 */
        int count255=0;
        for(int i=0;i<byTempMj.length;i++){
        	if(byTempMj[i]==255){
        		count255++;
        	}
        }
        if(count255>0){
        	return 0;
        }
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, byTempMj, Constants.HAND_MJ_MAX);


		MajHelper.SortCard(OriginalMj, Constants.HAND_MJ_MAX);
		int MjDuiZiCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {

			if (MajHelper.IsWTSZ(OriginalMj[i])) {// 不是财神
				if (OriginalMj[i] == OriginalMj[i + 1]) {
					MjDuiZiCount++;
					i++;
				}
			}
		}

		int cntHaoHuaDui = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 3; i++) {

			if (MajHelper.IsWTSZ(OriginalMj[i])) {
				if (OriginalMj[i] == OriginalMj[i + 1] && OriginalMj[i] == OriginalMj[i + 2]
						&& OriginalMj[i] == OriginalMj[i + 3]) {
					cntHaoHuaDui++;
				}
			}
		}
		MajHelper.SortCard(OriginalMj, Constants.HAND_MJ_MAX);
		if (MjDuiZiCount == 7) {
			if (cntHaoHuaDui == 0) {
				return Constants.QI_DUI_ZI;// 清七对
			}
			if (cntHaoHuaDui == 1) {
				return Constants.HAO_HUA_QI_DUI_ZI;// 豪华七对子
			}
			if (cntHaoHuaDui == 2) {
				return Constants.SHUANG_HAO_HUA_QI_DUI_ZI;// 双豪华七对子
			}			
			if (cntHaoHuaDui == 3) {
				return Constants.SAN_HAO_HUA_QI_DUI_ZI;// 三豪华七对子
			}
		}
		return 0;
	}

	public static boolean IsPengPengHu(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				total++;
			}
			default:
				break;
			}
		}
		if (total == Constants.MAX_BLOCK_NUM) {
			return true;
		} else {
			return false;
		}
	}

	// 全带幺
	public static boolean IsPaiXinQuanDaiYao(int tempMj[], HU hu) {
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_SUN: {
				if (hu.block[i].first % 10 != 1 && hu.block[i].first % 10 != 7) {
					return false;
				}
			}
				break;
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				if (hu.block[i].first % 10 != 1 && hu.block[i].first % 10 != 9) {
					return false;
				}
			}
				break;
			default: {
				return false;
			}
			}
		}
		if (hu.jiangMj >= 31 || (hu.jiangMj % 10 != 1 && hu.jiangMj % 10 != 9)) {
			return false;
		}
		return true;
	}

	// 混全带幺
	public static boolean IsPaiXinHunDaiYao(int tempMj[], HU hu) {
		boolean bZiPai = false;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if(MajHelper.IsWTSZ(hu.block[i].first))
			{
				switch (hu.block[i].style) {
				case Constants.BLOCK_CHI:
				case Constants.BLOCK_SUN: {
					if (hu.block[i].first % 10 != 1 && hu.block[i].first % 10 != 7) {
						return false;
					}
				}
					break;
				case Constants.BLOCK_PENG:
				case Constants.BLOCK_KE:
				case Constants.BLOCK_GANG:
				case Constants.BLOCK_AN_GANG:
				case Constants.BLOCK_BU_GANG:{
					if (IsZi(hu.block[i].first)) {
						bZiPai = true;
					} else if (hu.block[i].first % 10 != 1 && hu.block[i].first % 10 != 7) {
						return false;
					}
				}
					break;
				default: {
					return false;
				}
				}
			}
		}
		if (bZiPai || IsZi(hu.jiangMj)) {
			return true;
		}
		return false;
	}

	// 混老头
	public static boolean IsPaiXinHunLaoTou(int tempMj[], HU hu) {
		boolean bZiPai = false;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if(MajHelper.IsWTSZ(hu.block[i].first))
			{
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_SUN: {
				return false;
			}
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				if (IsZi(hu.block[i].first)) {
					bZiPai = true;
				} else if (hu.block[i].first % 10 != 1 && hu.block[i].first % 10 != 9) {
					return false;
				}
			}
				break;
			default: {
				return false;
			}
			}
			}
		}
		if (bZiPai || IsZi(hu.jiangMj)) {
			return true;
		}
		return false;
	}

	// 清一色
	public static boolean IsPaiXinQingYiSe(int tempMj[], HU hu) {
		int iWanCount = 0, iSuoCount = 0, iTongCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (IsWan(tempMj[i])) {
				iWanCount++;
			} else if (IsTong(tempMj[i])) {
				iTongCount++;
			} else if (IsSuo(tempMj[i])) {
				iSuoCount++;
			} else if (IsZi(tempMj[i])) {
				return false;
			}
		}
		if (iWanCount == Constants.HAND_MJ_MAX || iSuoCount == Constants.HAND_MJ_MAX
				|| iTongCount == Constants.HAND_MJ_MAX) {
			return true;
		}
		return false;
	}

	// 混一色
	public static boolean IsPaiXinHunYiSe(int tempMj[], HU hu) {
		int iWanCount = 0, iSuoCount = 0, iTongCount = 0, iZiCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (IsWan(tempMj[i])) {
				iWanCount++;
			} else if (IsTong(tempMj[i])) {
				iTongCount++;
			} else if (IsSuo(tempMj[i])) {
				iSuoCount++;
			} else if (IsZi(tempMj[i])) {
				iZiCount++;
			}
		}
		if (iZiCount == Constants.HAND_MJ_MAX) {
			return false;
		}
		if(iZiCount > 0)
		{
			if (iWanCount + iZiCount == Constants.HAND_MJ_MAX || iSuoCount + iZiCount == Constants.HAND_MJ_MAX
					|| iTongCount + iZiCount == Constants.HAND_MJ_MAX) {
				return true;
			}	
		}
		return false;
	}

	// 一气通贯
	public static boolean IsPaiXinYiQiTongGuan(int tempMj[], HU hu) {
		int bySunMj[] = new int[4];

		Constants.memset(bySunMj, Constants.INVALID_CARD, Constants.sizeof(bySunMj));

		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_SUN: {
				bySunMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		if (total >= 3) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				boolean bj3 = false;
				boolean bj6 = false;
				for (int j = i; j < Constants.MAX_BLOCK_NUM; j++) {
					if (i != j) {
						if (bySunMj[j] == bySunMj[i] + 3 && IsTongHuaSe(bySunMj[j], bySunMj[i])) {
							bj3 = true;
						}
						if (bySunMj[j] == bySunMj[i] + 6 && IsTongHuaSe(bySunMj[j], bySunMj[i])) {
							bj6 = true;
						}
					}
				}
				if (bj3 && bj6) {
					return true;
				}
			}
		}

		return false;
	}

	// 小三元
	public static boolean IsPaiXinXiaoSanYuan(int tempMj[], HU hu) {
		if (IsSanYuan(hu.jiangMj) == false) {
			return false;
		}
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsSanYuan(hu.block[i].first)) {
				total++;
			}
		}
		if (total == 2) {
			return true;
		}
		return false;
	}

	// 三色同顺
	public static boolean IsPaiXinSanSeTongShun(int tempMj[], HU hu) {
		int bySunMj[] = new int[5];

		Constants.memset(bySunMj, Constants.INVALID_CARD, Constants.sizeof(bySunMj));

		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_SUN: {
				bySunMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		if (total >= 3) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				boolean bjw = false;
				boolean bjt = false;
				for (int j = i; j < Constants.MAX_BLOCK_NUM; j++) {
					if (i != j) {
						if (MajHelper.IsWTSZ(bySunMj[j]) && bySunMj[j] == bySunMj[i] + 10) {
							bjw = true;
						}
						if (MajHelper.IsWTSZ(bySunMj[j]) && bySunMj[j] == bySunMj[i] + 20) {
							bjt = true;
						}
					}
				}
				if (bjw && bjt) {
					return true;
				}
			}
		}

		return false;
	}

	// 一色三顺
	public static boolean IsPaiXinYiSeSanShun(int tempMj[], HU hu) {
		int bySunMj[] = new int[4];

		Constants.memset(bySunMj, Constants.INVALID_CARD, Constants.sizeof(bySunMj));

		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_SUN: {
				bySunMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		if (total >= 3) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				int count = 0;
				for (int j = i; j < Constants.MAX_BLOCK_NUM; j++) {
					if (i != j) {
						if (MajHelper.IsWTSZ(bySunMj[j]) && bySunMj[j] == bySunMj[i]) {
							count++;
						}
					}
				}
				if (count == 3) {
					return true;
				}
			}
		}

		return false;
	}

	// 三色同刻
	public static boolean IsPaiXinSanSeTongKe(int tempMj[], HU hu) {
		int byKeMj[] = new int[4];

		Constants.memset(byKeMj, Constants.INVALID_CARD, Constants.sizeof(byKeMj));

		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				if (IsWST(hu.block[i].first)) {
					byKeMj[total++] = hu.block[i].first;
				}
			}
				break;
			default:
				break;
			}
		}
		if (total >= 3) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				boolean bjw = false;
				boolean bjt = false;
				for (int j = i; j < Constants.MAX_BLOCK_NUM; j++) {
					if (i != j) {
						if (MajHelper.IsWTSZ(byKeMj[j]) && byKeMj[j] == byKeMj[i] + 10) {
							bjw = true;
						}
						if (MajHelper.IsWTSZ(byKeMj[j]) && byKeMj[j] == byKeMj[i] + 20) {
							bjt = true;
						}
					}
				}
				if (bjw && bjt) {
					return true;
				}
			}
		}

		return false;
	}

	// 三暗刻
	public static boolean IsPaiXinSanAnKe(int tempMj[], HU hu) {
		if (GetPaiXinAnKe(tempMj, hu) == 3) {
			return true;
		}
		return false;
	}

	// 三连刻
	public static boolean IsPaiXinSanLianKe(int tempMj[], HU hu) {
		int byKeMj[] = new int[4];

		Constants.memset(byKeMj, Constants.INVALID_CARD, Constants.sizeof(byKeMj));

		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				if (IsZi(hu.block[0].first)) {
					return false;
				}
				byKeMj[total++] = hu.block[i].first;
			}
				break;
			default:
				break;
			}
		}
		if (total >= 3) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				int count = 0;
				for (int j = i; j < Constants.MAX_BLOCK_NUM; j++) {
					if (i != j) {
						if ((byKeMj[j] == byKeMj[i] + 1 && IsTongHuaSe(byKeMj[j], byKeMj[i] + 1))
								|| (byKeMj[j] == byKeMj[i] + 2 && IsTongHuaSe(byKeMj[j], byKeMj[i] + 2))) {
							count++;
						}
					}
				}
				if (count == 3) {
					return true;
				}
			}
		}

		return false;
	}

	// 三杠子
	public static boolean IsPaiXinSanGangZi(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_AN_GANG:
			case Constants.BLOCK_BU_GANG:{
				total++;
			}
				break;
			default:
				break;
			}
		}
		if (total == 3) {
			return true;
		}
		return false;
	}

	// 字一色
	public static boolean IsZiYiSe(int tempMj[], HU hu) {
		int total = 0;
		if (IsWST(hu.jiangMj)) {
			return false;
		}
		if (IsPaiXinQiDuiZi(tempMj) > 0) {
			for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
				if (!IsZi(tempMj[i])) {
					return false;
				}
			}
			return true;
		}
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_KE:
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG: {
				if (IsZi(hu.block[i].first)) {
					total++;
				} else {
					return false;
				}
			}
				break;
			default: {
				return false;
			}
			}
		}
		if (total == 4) {
			return true;
		}
		return false;
	}

	public static boolean IsSiAnKe(int handMj[], HU hu) {
		if (GetPaiXinAnKe(handMj, hu) == 4) {
			return true;
		}
		int total = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 2; i++) {
			if (MajHelper.IsWTSZ(handMj[i]) && handMj[i] == handMj[i + 1] && handMj[i + 1] == handMj[i + 2]) {
				total++;
				i += 2;
			}
		}
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_AN_GANG: {
				total++;
			}
			default:
				break;
			}
		}
		return false;
	}

	public static boolean IsDaSiXi(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsFeng(hu.block[i].first)) {
				total++;
			}
		}
		if (total == 4) {
			return true;
		}
		return false;
	}

	public static boolean IsXiaoSiXi(int tempMj[], HU hu) {
		if (IsFeng(hu.jiangMj) == false) {
			return false;
		}
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsFeng(hu.block[i].first)) {
				total++;
			}
		}
		if (total == 3) {
			return true;
		}
		return false;
	}

	public static boolean IsDaSanYuan(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsSanYuan(hu.block[i].first)) {
				total++;
			}
		}
		if (total == 3) {
			return true;
		}
		return false;
	}

	// 四连刻
	public static boolean IsSiLianKe(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if(MajHelper.IsWTSZ(hu.block[0].first))
			{
				switch (hu.block[i].style) {
				case Constants.BLOCK_PENG:
				case Constants.BLOCK_KE:
				case Constants.BLOCK_GANG:
				case Constants.BLOCK_BU_GANG:
				case Constants.BLOCK_AN_GANG: {
					if (IsZi(hu.block[0].first)) {
						return false;
					}
					total++;
				}
					break;
				default: {
					return false;
				}

				}
			}
		}
		if (total == 4) {
			if (IsTongHuaSe(hu.block[0].first, hu.block[1].first, hu.block[2].first)
					&& IsTongHuaSe(hu.block[1].first, hu.block[2].first, hu.block[3].first)) {
				if (hu.block[3].first == hu.block[2].first + 1 && hu.block[2].first + 1 == hu.block[1].first + 2
						&& hu.block[1].first + 2 == hu.block[0].first + 3) {
					return true;
				}
			} else {
				return false;
			}
		}
		return false;
	}

	// 四扛子
	public static boolean IsSiGangZi(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG:{
				total++;
			}
				break;
			default: {
				return false;
			}

			}
		}
		if (total == 4) {
			return true;
		}
		return false;
	}

	// 国士无双
	public static boolean IsGuoShiWuShuang(int tempMj[]) {
		if (GetPaiCount(tempMj) != Constants.HAND_MJ_MAX) {
			return false;
		}
		int intmpMj[] = new int[Constants.HAND_MJ_MAX];

		Constants.memset(intmpMj, Constants.INVALID_CARD, Constants.sizeof(intmpMj));

		Constants.memcpy(intmpMj, tempMj, Constants.HAND_MJ_MAX);
		int gswsMj[] = { 1, 9, 11, 19, 21, 29, 31, 32, 33, 34, 35, 36, 37, Constants.INVALID_CARD };
		// int mjCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {
			if (intmpMj[i] == intmpMj[i + 1]) {
				DeletePai(intmpMj, intmpMj[i]);
				break;
			}
		}
		SortCard(intmpMj, Constants.HAND_MJ_MAX);
		if (Constants.memcmp(intmpMj, gswsMj, Constants.HAND_MJ_MAX) == 0) {
			return true;
		}
		return false;
	}

	// 九莲宝灯
	public static boolean IsJiuLianBaoDeng(int tempMj[], HU hu) {
		if (GetPaiCount(tempMj) != Constants.HAND_MJ_MAX) {
			return false;
		}
		if (tempMj[0] + 8 == tempMj[Constants.HAND_MJ_MAX - 1]
				&& IsTongHuaSe(tempMj[0], tempMj[Constants.HAND_MJ_MAX - 1])) {
			boolean bYao = false;
			boolean bJiu = false;
			if (tempMj[0] == tempMj[1] && tempMj[1] == tempMj[2] && tempMj[0] % 10 == 1) {
				bYao = true;
			}
			if (tempMj[Constants.HAND_MJ_MAX - 1] == tempMj[Constants.HAND_MJ_MAX - 2]
					&& tempMj[Constants.HAND_MJ_MAX - 2] == tempMj[Constants.HAND_MJ_MAX - 3]
					&& tempMj[Constants.HAND_MJ_MAX - 1] % 10 == 9) {
				bJiu = true;
			}
			if (bYao && bJiu) {
				int intmpMj[] = new int[Constants.HAND_MJ_MAX];

				Constants.memset(intmpMj, Constants.INVALID_CARD, Constants.sizeof(intmpMj));

				Constants.memcpy(intmpMj, tempMj, Constants.HAND_MJ_MAX);
				DeletePai(intmpMj, tempMj[0], tempMj[1], tempMj[2]);
				DeletePai(intmpMj, tempMj[Constants.HAND_MJ_MAX - 1], tempMj[Constants.HAND_MJ_MAX - 2],
						tempMj[Constants.HAND_MJ_MAX - 3]);

				for (int j = 2; j < 9; j++) {
					int mjCount = 0;
					for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
						if (MajHelper.IsWTSZ(intmpMj[i]) && intmpMj[i] % 10 == j) {
							mjCount++;
							break;
						}
					}
					if (mjCount == 0) {
						return false;
					}
				}

				return true;
			}
		}

		return false;
	}

	// 清老头
	public static boolean IsQingLaoTou(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if(MajHelper.IsWTSZ(hu.block[i].first))
			{
				switch (hu.block[i].style) {
				case Constants.BLOCK_PENG:
				case Constants.BLOCK_KE:
				case Constants.BLOCK_GANG:
				case Constants.BLOCK_BU_GANG:
				case Constants.BLOCK_AN_GANG: {
					if (hu.block[i].first % 10 == 1 || hu.block[i].first % 10 == 9) {
						total++;
					}
				}
					break;
				default: {
					return false;
				}

				}
			}

		}
		if (total == 4) {
			if (hu.jiangMj % 10 == 1 || hu.jiangMj % 10 == 9) {
				return true;
			}
		}
		return false;
	}

	// 绿一色
	public static boolean IsLvYiSe(int tempMj[], HU hu) {
		// int lvMj[7]={19,20,21,38,38,32};
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if(MajHelper.IsWTSZ(hu.block[i].first))
			{
			switch (hu.block[i].style) {
			case Constants.BLOCK_SUN:
			case Constants.BLOCK_CHI: {
				if (hu.block[i].first != 22) {
					return false;
				}
			}
				break;
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG: {
				if (hu.block[i].first == 22 || hu.block[i].first == 23 || hu.block[i].first == 24
						|| hu.block[i].first == 26 || hu.block[i].first == 28 || hu.block[i].first == 36) {

				} else {
					return false;
				}
			}
				break;
			default: {
				return false;
			}

			}
			}
		}
		if (hu.jiangMj == 22 || hu.jiangMj == 23 || hu.jiangMj == 24 || hu.jiangMj == 26 || hu.jiangMj == 28
				|| hu.jiangMj == 36) {
			return true;
		}
		return false;
	}

	// 万绿一点红
	public static boolean IsWanLvYiDianHong(int tempMj[], HU hu) {
		// 10,11,12,14,16,31
		boolean bZhong = false;
		if (hu.jiangMj == 35) {
			bZhong = true;
		}

		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_SUN:
			case Constants.BLOCK_CHI: {
				if (hu.block[i].first != 22) {
					return false;
				}
			}
				break;
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG: {
				if (hu.block[i].first == 35) {
					bZhong = true;
				} else {
					if (hu.block[i].first == 22 || hu.block[i].first == 23 || hu.block[i].first == 24
							|| hu.block[i].first == 26 || hu.block[i].first == 28) {

					} else {
						return false;
					}
				}
			}
				break;
			default: {
				return false;
			}

			}
		}
		if (bZhong) {
			if (hu.jiangMj == 22 || hu.jiangMj == 23 || hu.jiangMj == 24 || hu.jiangMj == 26 || hu.jiangMj == 28
					|| hu.jiangMj == 35) {
				return true;
			}
		}
		return false;
	}

	// 红孔雀
	public static boolean IsHongKongQue(int tempMj[], HU hu) {
		// 9,13,15,17,31
		boolean bZhong = false;
		if (hu.jiangMj == 35) {
			bZhong = true;
		}
		// int hongMj[7]={18,22,24,26,31};
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_PENG:
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG: {
				if (hu.block[i].first == 21 || hu.block[i].first == 25 || hu.block[i].first == 27
						|| hu.block[i].first == 29 || hu.block[i].first == 35) {

				} else {
					return false;
				}
			}
				break;
			default: {
				return false;
			}

			}
		}
		if (hu.jiangMj == 21 || hu.jiangMj == 25 || hu.jiangMj == 27 || hu.jiangMj == 29 || hu.jiangMj == 35) {
			return true;
		}
		return false;
	}

	// 百万石
	public static boolean IsBaiWanShi(int tempMj[], HU hu) {
		int total = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			if (!IsWan(tempMj[i])) {
				return false;
			}
			total += tempMj[i];
		}
		if (total >= 100) {
			return true;
		}
		return false;
	}

	// 东北新干线
	public static boolean IsDongBeiXinGanXian(int tempMj[], HU hu) {
		if (!IsPaiXinYiQiTongGuan(tempMj, hu)) {
			return false;
		}
		if (hu.jiangMj != 31 && hu.jiangMj != 34) {
			return false;
		}
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			switch (hu.block[i].style) {
			case Constants.BLOCK_KE:
			case Constants.BLOCK_GANG:
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_AN_GANG: {
				if (hu.block[i].first == 31 || hu.block[i].first == 34) {
					return true;
				}
			}
			default:
				break;
			}
		}
		return false;
	}

	public static boolean IsDaCheLun(int tempMj[], HU hu) // 大车轮
	{
		int byDaCheLunMj[] = { 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18 };
		if (Constants.memcmp(byDaCheLunMj, tempMj, Constants.HAND_MJ_MAX) == 0) {
			return true;
		}
		return false;
	}

	public static boolean IsShuangLongQiangZhu(int tempMj[], HU hu) // 双龙抢珠
	{
		if (IsTong(hu.jiangMj)) {
			for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
				if (hu.block[3].style != Constants.BLOCK_SUN) {
					return false;
				}
			}
			if (hu.block[0].first + 3 == hu.block[1].first && hu.block[2].first + 3 == hu.block[3].first) {
				if (hu.block[0].first + 20 == hu.block[2].first) {
					return true;
				}
			}
		}
		return false;
	}

	public static boolean IsDaHu(int byHuType[]) {
		// 大胡算番
		for (int i = 30; i < 50; i++) {
			if (byHuType[i] == 13) {
				return true;			
			}
			;
		}
		return false;
	}

	public static boolean IsXiaoSanYuan(int tempMj[], HU hu) {
		if (IsSanYuan(hu.jiangMj) == false) {
			return false;
		}
		int total = 0;
		for (int i = 0; i < Constants.MAX_BLOCK_NUM; i++) {
			if (IsSanYuan(hu.block[i].first)) {
				total++;
			}
		}
		if (total == 2) {
			return true;
		}
		return false;
	}

//	public static boolean IsDuTing(int tempMj[], HU hu, int byMj) {
//		int intstMj[] = new int[Constants.HAND_MJ_MAX];
//		int Hua[] = new int[8];
//		Constants.memcpy(intstMj, tempMj, Constants.HAND_MJ_MAX);
//
//		SortCard(intstMj,  Constants.HAND_MJ_MAX);
//		int byCanHuMjCount = 0;
//		HU temphu = new HU();// 两个空胡
//		for (int i = 0; i < 34; i++) // 不对花牌进行比对
//		{
//			int byOutMj = m_testMjPai[i];
//			CleanHu(temphu);
//			if (IsHu(intstMj,  byOutMj, hu, temphu, Hua)) {
//				byCanHuMjCount++;
//				if (byCanHuMjCount == 2) {
//					return false;
//				}
//			}
//		}
//		SortCard(intstMj,  Constants.HAND_MJ_MAX);
//		return true;
//	}
	
	public static boolean IsPaiXinShouZhuaYi(int byHandMj[]) 
	{
		if(byHandMj[1] == Constants.INVALID_CARD)
		{
			return true;
		}
		return false;
	}
//	public static boolean IsKaWuXing(int byHandMj[], HU hu,HU temphu,int byMj) {
//	
//		// 排序牌面
//		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
//		Constants.memcpy(OriginalMj, byHandMj, Constants.HAND_MJ_MAX);
//		if (byMj != Constants.INVALID_CARD) {
//			OriginalMj[Constants.HAND_MJ_MAX - 1] = byMj;
//		}
//		
//		SortCard(OriginalMj, Constants.HAND_MJ_MAX);
//		
//		HU testHu = new HU();
//		for(int i=0;i<4;i++)
//		{
//			testHu.block[i].first = hu.block[i].first;
//			testHu.block[i].style = hu.block[i].style;
//		}
//
//		if (byMj == 5 || byMj == 15 || byMj == 25) {
//			if (Constants.countof(OriginalMj, byMj - 1) > 0 && Constants.countof(OriginalMj, byMj + 1) > 0) {
//				Constants.replace(OriginalMj, byMj - 1, Constants.INVALID_CARD, 1);
//				Constants.replace(OriginalMj, byMj, Constants.INVALID_CARD, 1);
//				Constants.replace(OriginalMj, byMj + 1, Constants.INVALID_CARD, 1);
//			
//			for (int i = 0; i < 4; i++) {
//				if (testHu.block[i].style == 0) {
//					testHu.block[i].first = 37;
//					testHu.block[i].style = Constants.BLOCK_CHI;
//					break;
//				}
//			}
//
//			HU outHu = new HU();
//			int byHuaPai[] = new int[8];
//			if (IsHu(OriginalMj, Constants.INVALID_CARD, testHu, outHu, byHuaPai)) {
//				return true;
//			}
//			}
//		}
//		return false;
//	}
    public static boolean IsMingSiGui(int tempHandMj[], HU hu,HU temphu,int byActivePai) {
		for(int i =0;i<Constants.MAX_BLOCK_NUM;i++)
		{	
			BLOCK block = hu.block[i];
			if(block.style==Constants.BLOCK_NULL){
				continue;
			}
			
    		if(block.style == Constants.BLOCK_PENG)
    		{
    			for(int k =0;k<Constants.HAND_MJ_MAX-1;k++){
    				if(block.first == tempHandMj[k] || block.first == byActivePai){
    					return true;
    				}
    			}
    		}
		}
		return false;
	}
    public static boolean IsAnSiGui(int byHandMj[], HU hu,HU temphu,int byMj) {
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, byHandMj, Constants.HAND_MJ_MAX);
		if (byMj != Constants.INVALID_CARD) {
			OriginalMj[Constants.HAND_MJ_MAX - 1] = byMj;
		}    	
		
		SortCard(OriginalMj, Constants.HAND_MJ_MAX);
    	for(int i =0;i<Constants.HAND_MJ_MAX-3;i++){
    		if(OriginalMj[i]==Constants.INVALID_CARD){
    			continue;
    		}
    		if(OriginalMj[i] == OriginalMj[i+3])
    		{
    			return true;
    		}
    	}
    	return false;
	  
   }
    //霍邱麻将添加规则
	private static int MjType_Wan = 1;
	private static int MJType_Tong = 2;
	private static int MjType_Suo = 3;
	private static int MJType_Zi = 4;
	public static int getMjType(int mj){
		if(mj >= 1 && mj <= 9)
			return MjType_Wan;
		else if(mj >= 11 && mj <= 19)
			return MJType_Tong;
		else if(mj >= 21 && mj <= 29)
			return MjType_Suo;
		else
			return MJType_Zi;
	}
	public static boolean IsMjCardMinSun(int card){
		return card == 1 || card == 11 || card == 21;
	}
	public static boolean IsMjCardMiddSun(int card){
		return card == 4 || card == 14 || card == 24;
	}
	public static boolean IsMjCardMaxSun(int card){
		return card == 7 || card == 17 || card == 27;
	}
	public static void testHuoQiuMJ(){
		int byTestChongtian [] = {11,12,13,14,15,16,17,18,19,11,11,12,12,255};
		int byTestSiGuiYi1 [] = {1,2,3,4,5,6,11,12,13,1,1,1,11,255};
		int byTestSiGuiYi2 [] = {1,2,3,4,5,6,2,2,2,1,1,1,11,255};
		int byTestSiGuiYi3 [] = {1,2,3,3,3,3,2,2,2,1,1,1,11,255};//这种情况下是七对胡
		int byTestXiaoQiDui [] = {1,1,2,2,3,3,4,4,5,5,6,6,11,255};//这种情况下是七对胡
		int byTestDuiDui1 [] = {1,1,1,2,2,2,4,4,4,5,5,5,11,255};//这种情况下是对对胡，小七对霍邱不算胡
		int byTestDuiDui2 [] = {1,1,1,2,2,2,4,4,4,31,31,31,11,255};//这种情况下是对对胡
		int byTestDuiDui3 [] = {1,1,1,2,2,2,4,4,4,31,31,31,11,255};//这种情况下是对对胡
		int byTestDuiDui4 [] = {1,1,1,1,2,2,2,2,31,31,31,31,11,255};//这种情况下不胡，不是豪华小七对
		int byTestBaoPao1 [] = {1,2,3,2,3,4,5,6,7,7,8,9,5,255};//这种情况下不胡，不是豪华小七对
		int byTestQuanYaoJiu1 [] = {1,1,1,9,9,9,31,31,31,11,11,11,32,255};//全幺九
		MajSide testMajSide = new MajSide();
		testMajSide.Init();
		testMajSide.Maj = byTestQuanYaoJiu1;
		testMajSide.SortCard();
		HU tempHu = new HU();
		MajHelper.CleanHu(tempHu);
		
		int byTempMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(byTempMj, testMajSide.Maj, Constants.HAND_MJ_MAX);
//		boolean isHu = MajHelper.IsHu(testMajSide.Maj,32, testMajSide.hu, tempHu, testMajSide.Hua);
//		System.out.println("胡牌么:" + isHu);
		if(false){
			boolean isChongtian = MajHelper.IsPaiXinChongTian(byTempMj, tempHu);
			System.out.println("是冲天:" + isChongtian);
		}
		if(false){
			int count = MajHelper.IsPaiXinSiGuiYi(byTempMj, tempHu);
			System.out.println("四归一:" + count);
		}
		if(false){
			int qiDui = MajHelper.IsPaiXinHQDuiDuiHu(byTempMj,11);
			System.out.println("对对胡:" + qiDui);
		}
		if(false){
			boolean bao = MajHelper.IsPaiXinBaoPai(byTempMj, tempHu,5);
			System.out.println("包牌:" + bao);
		}
		if(true){
			boolean bao = MajHelper.IsPaiXinQuanYaoJiu(tempHu);
			System.out.println("全幺九:" + bao);
		}
		System.exit(0);
	}
	//一炮三响
    public static boolean IsPaiXinYiPaoSanXiang(int tempMj[],HU hu){
    	return true;
    }
    //豹子
    public static boolean IsPaiXinBaoZi(int tempMj[],HU hu){
    	return true;
    }
    public static boolean IsPaiXinQuanYaoJiu(HU hu){
		int samecount = 0;
		if(IsZi(hu.jiangMj) || hu.jiangMj % 10 == 1 || hu.jiangMj % 10 == 9){
			for(int i = 0;i < Constants.MAX_BLOCK_NUM;i++){
				BLOCK block = hu.block[i];
				switch(block.style){
				case Constants.BLOCK_KE:
				case Constants.BLOCK_GANG:
				case Constants.BLOCK_PENG:
				case Constants.BLOCK_AN_GANG:
				case Constants.BLOCK_BU_GANG:{
					int card = block.first;
					if(IsZi(card) || card % 10 == 1 || card % 10 == 9){
						samecount++;
					}
					break;
				}
				}
			}
			if(samecount == 4){
				return true;
			}
		}
		return false;
    }
    public static boolean IsPaiXinBaoPaiForQuanYaoJiu(int tempMj[],HU hu,int byMj){
    	int chipengcount = 0;
		for(int j = 0;j < Constants.MAX_BLOCK_NUM;j++){
			BLOCK block = hu.block[j];
			switch(block.style){
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_PENG:{
				chipengcount++;
				break;
			}
			//暗杠不算
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_GANG:{
				chipengcount++;
				break;
			}
			}
		}
		if(chipengcount >= 3)
			return true;
		else
			return false;
    }
    public static boolean IsPaiXinBaoPai(int tempMj[],HU hu,int byMj){
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, tempMj, Constants.HAND_MJ_MAX);
		if(OriginalMj[tempMj.length - 1] == Constants.INVALID_CARD && byMj != Constants.INVALID_CARD){
			OriginalMj[tempMj.length - 1] = byMj;
		}
		if(IsPaiXinQingYiSe(OriginalMj,hu) == false){
			return false;
		}
		int chipengcount = 0;
		for(int j = 0;j < Constants.MAX_BLOCK_NUM;j++){
			BLOCK block = hu.block[j];
			switch(block.style){
			case Constants.BLOCK_CHI:
			case Constants.BLOCK_PENG:{
				chipengcount++;
				break;
			}
			//暗杠不算
			case Constants.BLOCK_BU_GANG:
			case Constants.BLOCK_GANG:{
				chipengcount++;
				break;
			}
			}
		}
		if(chipengcount >= 3)
			return true;
		else
			return false;
    }
	public static int IsPaiXinHQDuiDuiHu(int tempMj[],int byMj){
		int OriginalMj[] = new int[Constants.HAND_MJ_MAX];
		Constants.memcpy(OriginalMj, tempMj, Constants.HAND_MJ_MAX);
		if(OriginalMj[tempMj.length - 1] == Constants.INVALID_CARD && byMj != Constants.INVALID_CARD){
			OriginalMj[tempMj.length - 1] = byMj;
		}

		MajHelper.SortCard(OriginalMj, Constants.HAND_MJ_MAX);
		int MjDuiZiCount = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 1; i++) {

			if (MajHelper.IsWTSZ(OriginalMj[i])) {// 不是财神
				if (OriginalMj[i] == OriginalMj[i + 1]) {
					MjDuiZiCount++;
					i++;
				}
			}
		}

		int cntHaoHuaDui = 0;
		for (int i = 0; i < Constants.HAND_MJ_MAX - 2; i++) {
			if (MajHelper.IsWTSZ(OriginalMj[i])) {
				if (OriginalMj[i] == OriginalMj[i + 1] && OriginalMj[i] == OriginalMj[i + 2]) {
					cntHaoHuaDui++;
					i += 2;
				}
			}
		}
		if(MjDuiZiCount == 5 && cntHaoHuaDui == 4){
			return 1;
		}else{
			return -1;
		}
	}
    public static int IsPaiXinSiGuiYi(int tempMj[], HU hu) {
    	int count = 0;
    	List<Integer> has3 = new ArrayList<Integer>();
    	for(int i = 0;i < Constants.HAND_MJ_MAX - 3;i++){
    		if(tempMj[i] == tempMj[i+1] && tempMj[i] == tempMj[i+2]){
    			if(has3.indexOf(tempMj[i]) == -1)
    				has3.add(tempMj[i]);
    		}
    	}
    	for(int i = 0;i < has3.size();i++){
    		int card = has3.get(i);
    		int seqvalidcount = 0;
    		int same3validcount = 0;
    		for(int j = 0;j < Constants.MAX_BLOCK_NUM;j++){
    			BLOCK block = hu.block[j];
    			if(block.first == card){
    				switch(block.style){
    				case Constants.BLOCK_CHI:
    				case Constants.BLOCK_SUN:{
    					seqvalidcount++;
    					break;
    				}
    				case Constants.BLOCK_KE:
    				case Constants.BLOCK_PENG:{
    					same3validcount++;
    					break;
    				}
    				}
    			}
    			//顺子结构不仅第一张，第二张，三张都算的
    			//吃结构第一张第二张一样都算的
    			if(block.style == Constants.BLOCK_SUN && (card == block.first + 1 || card == block.first + 2)){
    				seqvalidcount++;
    			}else if(block.style == Constants.BLOCK_CHI && (card == block.first + 1 || card == block.first + 2)){
    				seqvalidcount++;
    			}
    		}
    		if(seqvalidcount == 1 && same3validcount == 1){
    			count++; 
    		}
    	}
    	return count;
    }
    public static boolean IsPaiXinChongTian(int tempMj[],HU hu){
    	int blockcount = 0;
    	List<Integer> cardValue = new ArrayList<Integer>();
    	for(int i = 0;i < Constants.MAX_BLOCK_NUM;i++){
    		BLOCK block = hu.block[i];
    		switch(block.style){
    		case Constants.BLOCK_CHI:
    		case Constants.BLOCK_SUN:{
    			blockcount++;
    			cardValue.add(block.first);
    			break;
    		}
    		}
    	}
    	if(blockcount < 3){
    		return false;
    	}
    	//必须含有123,456,789才行
    	for(int i = 0;i < cardValue.size();i++){
    		if(IsMjCardMinSun(cardValue.get(i))){
    			int se = getMjType(cardValue.get(i));
    			boolean has4 = false,has7 = false;
    			for(int j = 0;j < cardValue.size();j++){
    				if(i == j)
    					continue;
    				int card = cardValue.get(j);
    				if(IsMjCardMiddSun(card)){
    					if(se == getMjType(card))
    						has4 = true;
    				}
    				if(IsMjCardMaxSun(card)){
    					if(se == getMjType(card))
    						has7 = true;
    				}
    			}
    			if(has4 && has7)
    				return true;
    		}
    	}
    	return false;
    }
    
    //1也可以当14，每张牌最多5张
    public boolean hasShunZi(int tempMj[]){
    	int byTest3[] = { 1, 2,3,4, 5, 6, 7, 8,9, 10, 11, 12,13 };
    	tempMj = byTest3;
    	
    	return false;
    }
}
